<template>
	<view class="notice" :style="Style">
		<!-- 公告 -->
		<!-- <van-notice-bar
      :text="datas.noticeText"
      left-icon="volume-o"
      :background="datas.backColor"
      :color="datas.textColor"
    /> -->

		<gui-speaker :items="items">
			<template v-slot:icon>
				<view class="gonggao" @click="gonggao">
					<image style="width: 120rpx; height: 80rpx;" src="@/static/gg.png" alt=""></image>
					<!--  class="gui-block demo-icon gui-primary-color" -->
					<view class="scroll-container">
						<view id="scroll-text" v-if="datas.noticeText.length > 16">
							{{datas.noticeText}}
						</view>
						<view style="white-space: nowrap;" v-else>
							{{datas.noticeText}}
						</view>
					</view>
					<view style="width: 55rpx; font-size: 25rpx; margin-left: 35rpx; color: #1C95F1;">更多</view>
				</view>
			</template>
		</gui-speaker>

	</view>
</template>

<script>
	export default {
		name: 'notice',
		props: {
			datas: {
				type: Object,
				default: () => {
					return {
						text: '公告',
						noticeText: '请填写内容，如果过长，将会在手机上滚动显示', //内容
						backColor: 'rgb(255, 248, 233)', //背景颜色
						textColor: 'rgba(100, 101, 102)', //文字颜色
						imageList: ["公告"]
					}
				}
			},
		},
		data() {
			return {
				items: [],
				Style: {}
			}
		},
		watch: {
			datas: {
				handler(newVal, oldVal) {
					//this.set_items();
					this.datas = newVal;
					this.set_items(newVal.imageList);
				},
				deep: true
			}
		},
		beforeCreate() {

		},
		created() {
			this.Style = this.get_style();
			// if(this.datas.hasOwnProperty("items"))
			// {
			//  this.items=this.datas.items;
			// }
			this.set_items(this.datas.imageList);
			console.log('字符串长度：', this.datas.noticeText.length);
		},
		methods: {
			set_items(d) {
				if (d) {
					this.items = d;
					console.log("notice->set_items>datas", this.items);
				}
			},
			get_style() {
				let s = this.datas;
				s.backgroundColor = this.datas.backColor
				s.color = this.datas.textColor
				return this.$comm.getCss(s);
			},
			gonggao() {
				uni.navigateTo({
					url: '/pages/home/notice/index'
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.notice {
		position: relative;
		border-bottom-left-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
		box-shadow: 3rpx 5rpx 8rpx rgba(0, 0, 0, 0.2);
	}

	.gonggao {
		display: flex;
		align-items: center;
		padding: 15rpx 6rpx;
		border-top: 1px solid #d8d8d8;
		width: 625rpx;
		margin-left: 20rpx;
	}

	.scroll-container {
		width: 430rpx;
		font-size: 28rpx;
		/* 设置容器宽度，根据需要进行调整 */
		overflow: hidden;
		/* 隐藏超出容器宽度的文字 */
		margin-left: 15rpx;
	}

	#scroll-text {
		white-space: nowrap;
		/* 设置文字不换行 */
		display: inline-block;
		/* 必须将文字包裹在一个块级元素中，才能进行动画效果 */
		animation: scroll-left 8s linear infinite;
		/* 设置文字动画效果 */
	}

	@keyframes scroll-left {
		0% {
			transform: translateX(100%);
			/* 初始位置为容器宽度的100%，文字隐藏在容器右侧 */
		}

		100% {
			transform: translateX(-100%);
			/* 结束位置为容器宽度的-100%，文字完全滚出容器左侧 */
		}
	}
</style>